/**
 * karin 2017.03.24
 */
import { TAX_CHECK_INFO, GET_VAILL_INFO, CHECK_ASSOCIATED_INFO } from "./actionsTypes"
import taxCheckInfoService from '../services/taxCheckInfoService'

import { Toast } from 'antd-mobile'

export const taxCheckInfo = data => ({ type: TAX_CHECK_INFO, data: data });//选中的车牌号码

export const getvaillInfo = data => ({ type: GET_VAILL_INFO, data: data });//接口返回的资料条件

export const checkAssociatedInfo = data => ({ type: CHECK_ASSOCIATED_INFO, data: data });//被选中的资料条件


export const getvaillData = (data,callBack) => {
    return (dispatch,getState) => {
        Toast.hide();
        Toast.loading("", 30, () => Toast.info("网络错误", 2));
        taxCheckInfoService.getvaillData(data).then(resultData => {
            Toast.hide();
            if (resultData.code == 1000) {
                let data = resultData.data.requirements
                let newDATA=[]
                for(let item of data) {
                    let array=item.img.split('，')||item.img.split(',')||[];
                    newDATA.push({'name':item.name,'img':array})
                }
       
                dispatch(getvaillInfo(newDATA))
                callBack(data.length)
            }
            else {
                Toast.info(resultData.msg, 2);
            }
        });
    }
};

export const setRequirementStatus=(data,callBack) => {
    return (dispatch, getState) => {
        Toast.hide();
        Toast.loading("", 30, () => Toast.info("网络错误", 2));
        taxCheckInfoService.setRequirementStatus(data).then((result)=>{
            Toast.hide();
            if (result.code == 1000) {
                if(result.data.resultFlag==1){
                    callBack();
                }
            }
            else{
                Toast.info(result.msg, 2);
            }
        })
    }
};

//查看交强险有效日期
export const getInsuranceDate=(data,callBack)=>{
    return (dispatch, getState) => {
        Toast.hide();
        Toast.loading("", 30, () => Toast.info("网络错误", 2));
        taxCheckInfoService.getInsuranceDate(data).then((result)=>{
            Toast.hide();
            if (result.code == 1000) {
                callBack(result.data.insuranceDate);
            }
            else{
                Toast.info(result.msg, 2);
            }
        });
    }
};
